import { faker } from '@faker-js/faker';
import { delay, http } from 'msw';
import { formateSuccessResp } from '../utils';
import { MarketApi } from '@/api/services/marketService';
const areas =  [
  {
    code: '001',
    name: '北京',
  },
  {
    code: '002',
    name: '上海',
  },
  {
    code: '003',
    name: '广州',
  },
];

const gpus = [
  {
    name: 'H100 80GB SXM5 * 8',
    tag: ['性能王者'],
  },
  {
    name: 'H100 80GB SXM5 * 4',
  },
  {
    name: 'H100 80GB SXM5 * 2',
    tag: ['AI训练模型'],
  },
];

const cpus = [
  {
    name: 'Intel Xeon 8280',
    key: 1,
  },
  {
    name: 'Intel Xeon 8260',
    key: 2,
  },
  {
    name: 'Intel Xeon 8256',
    key: 3,
  },
];

const disks = [
  {
    name: 'HDD 5GB 4 SATA 400GB^3 NVMES 480GB * 2',
    key: 1,
  },
  {
    name: 'HDD 5GB 4 SATA 400GB^3 NVMES 480GB * 4',
    key: 2,
  },
  {
    name: 'HDD 5GB 4 SATA 400GB^3 NVMES 480GB * 6',
    key: 3,
  },
];


const memorys = [
  {
    name: 'DDR3 3GB * 5',
    key: 1,
  },
  {
    name: 'DDR3 3GB * 3',
    key: 2,
  },
  {
    name: 'DDR3 3GB * 1',
    key: 3,
  },
];

const marketList = http.get(`/api${MarketApi.list}`, async ({ request }:any) => {
  const url = new URL(request.url);
  const page = url.searchParams.get('page');
  const pageSize = url.searchParams.get('pageSize') ? Number(url.searchParams.get('pageSize')) : 10;
  await delay(2000);
  const total = 50;
  return formateSuccessResp({
    total,
    page,
    pageSize,
    list: Array.from({ length: pageSize }).map(() => ({
      // area: areas[faker.number.float({ min: 1, max: areas.length - 1, multipleOf: 1 })].name,
      area: faker.helpers.arrayElement(areas).name,
      gpu: faker.helpers.arrayElement(gpus),
      cpu: faker.helpers.arrayElement(cpus),
      disk: faker.helpers.arrayElement(disks),
      memory: faker.helpers.arrayElement(memorys),
      id: faker.string.uuid(),
      'listing-time': faker.date.recent().toISOString(),
      price: `${faker.number.float({
        min: 1000,
        max: 4000,
        fractionDigits: 0,
      })} ~ ${faker.number.float({ min: 5000, max: 9000, fractionDigits: 0 })}`,
      count: faker.number.float({ min: 1, max: 100, multipleOf: 1 }),
    })),
  });
});

export default [marketList];
